﻿using System.ComponentModel;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;

namespace AgLux
{
    /// <summary>
    /// //
    /// </summary>

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    [ScriptService]
    public class Service : WebService
    {
        /// <summary>
        /// //
        /// </summary>

        /// <param name="html">
        /// //
        /// </param>

        /// <returns>
        /// //
        /// </returns>

        [WebMethod]
        public string CreatePrintable(string html)
        {
            StreamWriter writer = new StreamWriter(HttpContext.Current.Request.PhysicalApplicationPath.Replace("\\", "/") + "Printable.html", false, Encoding.Unicode);

            writer.Write("<html><head><title>Printable</title></head><body>" + html + "</body></html>");
            writer.Close();

            return "Printable.html";
        }

        /// <summary>
        /// //
        /// </summary>

        [WebMethod]
        public void DeletePrintable()
        {
            File.Delete(HttpContext.Current.Request.PhysicalApplicationPath.Replace("\\", "/") + "Printable.html");
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="transcript">
        /// //
        /// </param>

        /// <returns>
        /// //
        /// </returns>

        [WebMethod]
        public string CreateTranscript(string transcript)
        {
            StreamReader reader = new StreamReader(HttpContext.Current.Request.PhysicalApplicationPath.Replace("\\", "/") + transcript);
            StreamWriter writer = new StreamWriter(HttpContext.Current.Request.PhysicalApplicationPath.Replace("\\", "/") + "Transcript.html", false, Encoding.Unicode);

            writer.Write("<html><head><title>Transcript</title></head><body>" + reader.ReadToEnd().Replace("\n", "<br/>") + "</body></html>");
            reader.Close();
            writer.Close();

            return "Transcript.html";
        }

        /// <summary>
        /// //
        /// </summary>

        [WebMethod]
        public void DeleteTranscript()
        {
            File.Delete(HttpContext.Current.Request.PhysicalApplicationPath.Replace("\\", "/") + "Transcript.html");
        }
    }
}
